﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Outpatient
{
    /// <summary>
    /// 门诊结算类别服务
    /// </summary>
    public class OtpSetlTypeService : CrudAppService<OtpSetlType, OtpSetlTypeDto, Guid, OtpSetlTypeInput, OtpSetlTypeCreateDto, OtpSetlTypeUpdateDto>, IOtpSetlTypeService
    {
        private IRepository<OtpSetlType, Guid> _optRgstTypeRepository;

        public OtpSetlTypeService(IRepository<OtpSetlType, Guid> optRgstTypeRepository) : base(optRgstTypeRepository)
        {
            _optRgstTypeRepository = optRgstTypeRepository;
        }

        public override async Task<PagedResultDto<OtpSetlTypeDto>> GetListAsync(OtpSetlTypeInput input)
        {
            var iQuery = await _optRgstTypeRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<OtpSetlType>, List<OtpSetlTypeDto>>(iQuery.ToList());

                return new PagedResultDto<OtpSetlTypeDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<OtpSetlType>, List<OtpSetlTypeDto>>(items.ToList());

                return new PagedResultDto<OtpSetlTypeDto>(totalCount, itemsDto);
            }
        }
    }
}
